const baseurl = "http://oai.huat.edu.cn:6302"
// const baseurl = "http://10.20.73.136:6302"


const request = (opitons) => {
	return new Promise((resolve, reject) => {
		if (opitons.method == "GET") {
			uni.request({
				url: `${baseurl}${opitons.url}`,
				data: opitons.data,
				method: opitons.method,
				header: {
					'Authorization': `${uni.getStorageSync("token_type")} ${uni.getStorageSync("access_token")}`
				},
				success: (res) => {
					return resolve(res.data)
				},
				fail: (error) => {
					return reject(error)
				}
			});
		}
		if (opitons.method == "POST") {
			uni.request({
				url: `${baseurl}${opitons.url}`,
				data: opitons.data,
				method: opitons.method,
				header: {
					'content-type': 'application/json',
					'Authorization': `${uni.getStorageSync("token_type")} ${uni.getStorageSync("access_token")}`
				},
				success: (res) => {
					return resolve(res.data)
				},
				fail: (error) => {
					return reject(error)
				}
			});
		}
	})
}

export default request